#ifndef _EMU2212_H_
#define _EMU2212_H_
  
#define SCC_STANDARD 0
#define SCC_ENHANCED 1

#define SCC_MASK_CH(x) (1<<(x))

typedef struct __SCC {

  UINT32 clk, rate ,base_incr, quality ;

  INT32 out, prev, next;

  UINT32 type ;
  UINT32 mode ;
  UINT32 active;
  UINT32 base_adr;
  UINT32 mask ;
  
  UINT32 realstep ;
  UINT32 scctime ;
  UINT32 sccstep ;

  UINT32 incr[5] ;

  UINT8  wave[5][32] ;

  UINT32 count[5] ;
  UINT32 freq[5] ;
  UINT32 phase[5] ;
  UINT32 volume[5] ;
  UINT32 offset[5] ;
  UINT8 reg[0x100-0xC0];

  char invert[5];
  char pan[5];

  UINT32 soutar[2],sout1,sout2;

  int ch_enable ;
  int ch_enable_next ;

  int cycle_4bit ;
  int cycle_8bit ;
  int refresh ;
  int rotate[5] ;

  unsigned char checkDone;

} SCC ;

class CKonamiSCC : public CBaseSoundDevice {

	private:
  		  UINT32 clk, rate ,base_incr, quality ;
		  INT32 out, prev, next;
		  UINT32 type ;
		  UINT32 mode ;
		  UINT32 active;
		  UINT16 base_adr;
		  UINT32 mask ;
		  UINT32 realstep ;
		  UINT32 scctime ;
		  UINT32 sccstep ;
		  UINT32 incr[5] ;
		  UINT8  wave[5][32] ;
		  UINT32 count[5] ;
		  UINT32 freq[5] ;
		  UINT32 phase[5] ;
		  UINT32 volume[5] ;
		  UINT32 offset[5] ;
		  UINT8 reg[0x100-0xC0];
		  char inbvert[5];
		  char pan[5];
		  INT32 soutar[2],sout1,sout2;
		  int ch_enable ;
		  int ch_enable_next ;
		  int cycle_4bit ;
		  int cycle_8bit ;
		  int refresh ;
		  int rotate[5] ;
		  unsigned char checkDone;

	private: // private functions
		void SetQuality(UINT32 quality);
		void WriteReg(UINT32 o, UINT32 d);
		UINT32 ReadReg(UINT32 adr);
		void internal_refresh();
		void SetRate(UINT32 r);
		INLINE void calc_stereo (int output[2]);
		void write_enhanced(UINT32 address, UINT32 value);
		void write_standard (UINT32 adr, UINT32 val);
		UINT32 read_enhanced (UINT32 adr);
		UINT32 read_standard (UINT32 adr);
		void Mix_Frame(int in, int out[2], int pan, int invert);

	public: // SMSE2K Calls
		void Init(CMixer* mixer, UINT32 c); 
		int Buffer(short** buf, int length);
		void Write(UINT64 adr, UINT8 val);
		UINT8 Read(UINT64 adr);
		void Shutdown();
		void Reset();
};

/*
EMU2212_API SCC *SCC_new(e_uint32 c, e_uint32 r) ;
EMU2212_API void SCC_reset(SCC *scc) ;
EMU2212_API void SCC_set_rate(SCC *scc, e_uint32 r);
EMU2212_API void SCC_set_quality(SCC *scc, e_uint32 q) ;
EMU2212_API void SCC_set_type(SCC *scc, e_uint32 type) ;
EMU2212_API void SCC_delete(SCC *scc) ;
EMU2212_API void SCC_set_pan (SCC *scc, int ch, int pan);
EMU2212_API void SCC_calc_stereo(SCC * scc, int output[2]);
EMU2212_API e_int16 SCC_calc(SCC *scc) ;
EMU2212_API void SCC_write(SCC *scc, e_uint32 adr, e_uint32 val) ;
EMU2212_API void SCC_writeReg(SCC *scc, e_uint32 adr, e_uint32 val) ;
EMU2212_API e_uint32 SCC_read(SCC *scc, e_uint32 adr) ;
EMU2212_API e_uint32 SCC_setMask(SCC *scc, e_uint32 adr) ;
EMU2212_API e_uint32 SCC_toggleMask(SCC *scc, e_uint32 adr) ;
*/


#endif
